//
//  RecommendCollectionViewCell.m
//  A_GOGO
//
//  Created bhomeM Liuiu on 16/1/18.
//  Copyright © 2016年 www.lanou3g.com. All rights reserved.
//

#import "RecommendCollectionViewCell.h"
#import "UIColor+Wonderful.h"
#import <UIImageView+WebCache.h>

@interface RecommendCollectionViewCell ()


@property (nonatomic, retain)UIImageView *image;

@property (nonatomic, retain)UIImageView *biaoqian;
@property (nonatomic, retain)UIImageView *biaotou;
@property (nonatomic, retain)UIImageView *imga;
@property (nonatomic, retain)UIImageView *imgb;
@property (nonatomic, retain)UIImageView *imgc;
@property (nonatomic, retain)UIImageView *imgd;
@property (nonatomic, retain)UIImageView *imge;
@property (nonatomic, retain)UILabel *price;
@property (nonatomic, retain)UILabel *gname;
@property (nonatomic, retain)UILabel *language;
@property (nonatomic, retain)UILabel *desc;
@property (nonatomic, retain)UIImageView *biao;

@end

@implementation RecommendCollectionViewCell

//初始化
- (instancetype)initWithFrame:(CGRect)frame
{
    self = [super initWithFrame:frame];
    if (self) {
        //biaoqian
        self.biaoqian = [[UIImageView alloc] init];
        _biaoqian.image = [UIImage imageNamed:@"biaoqian"];
        [self.contentView addSubview:_biaoqian];
        [_biaoqian release];
        
        //biaotou
        self.biaotou = [[UIImageView alloc] init];
        _biaotou.image = [UIImage imageNamed:@"quan"];
        [self.contentView addSubview:_biaotou];
        [_biaotou release];
        
        //评分"星"
        self.imga = [[UIImageView alloc]init];
      
        [self.contentView addSubview:_imga];
        [_imga release];
        
        self.imgb =[[UIImageView alloc]init];
     
        [self.contentView addSubview:_imgb];
        [_imgb release];
        
        self.imgc = [[UIImageView alloc]init];
       
        [self.contentView addSubview:_imgc];
        [_imgc release];
        
        self.imgd =[[UIImageView alloc]init];
       
        [self.contentView addSubview:_imgd];
        [_imgd release];
        
        self.imge =[[UIImageView alloc]init];

        [self.contentView addSubview:_imge];
        [_imge release];
        
        self.gname =[[UILabel alloc]init];
        _gname.font = [UIFont systemFontOfSize:16];
        [self.contentView addSubview:_gname];
        [_gname release];
        
        self.language =[[UILabel alloc]init];
        _language.textColor = [UIColor grayColor];
        [self.contentView addSubview:_language];
        [_language release];
        
        self.desc =[[UILabel alloc]init];
        _desc.backgroundColor = [UIColor gainsboroColor];
        _desc.textAlignment = NSTextAlignmentRight;
        _desc.font = [UIFont systemFontOfSize:14];
        _desc.textColor = [UIColor darkGrayColor];
        [self.contentView addSubview:_desc];
        [_desc release];
        
        
        
        //price
        self.price = [[UILabel alloc]init];
        _price.backgroundColor = [UIColor clearColor];
        _price.textColor = [UIColor whiteColor];
        _price.font = [UIFont systemFontOfSize:11];
        [self.contentView addSubview:_price];
        [_price release];
        
        //biao
        self.biao = [[UIImageView alloc]init];
        
        [self.contentView addSubview:_biao];
        [_biao release];
        //image
        self.image = [[UIImageView alloc] init];
       
        [self.contentView addSubview:_image];
        [_image release];
    }
    return self;
}

//今日推荐
-(void)setHomeM:(HomeModel *)homeM
{
    if (_homeM == homeM) {
        return;
    }
    [_homeM release];
    _homeM = [homeM retain];
    
    
    [self.image sd_setImageWithURL:[NSURL URLWithString:homeM.img]];
    self.gname.text = homeM.gname;
    self.language.text = homeM.language;
    self.desc.text = homeM.desc;
    
    if (homeM.score.floatValue > 2 && homeM.score.floatValue <= 2.5) {
        self.imga.image = [UIImage imageNamed:@"xing"];
        self.imgb.image = [UIImage imageNamed:@"xing"];
        self.imgc.image = [UIImage imageNamed:@"banxing"];
        self.imgd.image = [UIImage imageNamed:@"kongxing"];
        self.imge.image = [UIImage imageNamed:@"kongxing"];
    }
    if (homeM.score.floatValue > 2.5 && homeM.score.floatValue <= 3) {
        self.imga.image = [UIImage imageNamed:@"xing"];
        self.imgb.image = [UIImage imageNamed:@"xing"];
        self.imgc.image = [UIImage imageNamed:@"xing"];
        self.imgd.image = [UIImage imageNamed:@"kongxing"];
        self.imge.image = [UIImage imageNamed:@"kongxing"];
    }
    if (homeM.score.floatValue > 3 && homeM.score.floatValue <= 3.5) {
        self.imga.image = [UIImage imageNamed:@"xing"];
        self.imgb.image = [UIImage imageNamed:@"xing"];
        self.imgc.image = [UIImage imageNamed:@"xing"];
        self.imgd.image = [UIImage imageNamed:@"banxing"];
        self.imge.image = [UIImage imageNamed:@"kongxing"];
    }
    if (homeM.score.floatValue > 3.5 && homeM.score.floatValue <= 4) {
        self.imga.image = [UIImage imageNamed:@"xing"];
        self.imgb.image = [UIImage imageNamed:@"xing"];
        self.imgc.image = [UIImage imageNamed:@"xing"];
        self.imgd.image = [UIImage imageNamed:@"xing"];
        self.imge.image = [UIImage imageNamed:@"kongxing"];
    }
    if (homeM.score.floatValue > 4 && homeM.score.floatValue <= 4.5) {
        self.imga.image = [UIImage imageNamed:@"xing"];
        self.imgb.image = [UIImage imageNamed:@"xing"];
        self.imgc.image = [UIImage imageNamed:@"xing"];
        self.imgd.image = [UIImage imageNamed:@"xing"];
        self.imge.image = [UIImage imageNamed:@"banxing"];
    }
    if (homeM.score.floatValue > 4.5 && homeM.score.floatValue <= 5) {
        self.imga.image = [UIImage imageNamed:@"xing"];
        self.imgb.image = [UIImage imageNamed:@"xing"];
        self.imgc.image = [UIImage imageNamed:@"xing"];
        self.imgd.image = [UIImage imageNamed:@"xing"];
        self.imge.image = [UIImage imageNamed:@"xing"];
    }
    //    判断标签
    if (homeM.free.floatValue == 1) {
        self.price.text = @"免费";
        self.biao.image = [UIImage imageNamed:@"qianbi"];
//        
        self.biaoqian.image = [UIImage imageNamed:@"biaoqian"];
    }
    if (homeM.limitfree.floatValue == 1) {
        self.price.text = @"限免";
        self.biao.image = [UIImage imageNamed:@"naoling"];
        self.biaoqian.image = [UIImage imageNamed:@"biaoqianhon"];
    }
    if (!homeM.price.floatValue == 0 && homeM.free.floatValue ==0) {
        
        NSString *str = @"￥";
        NSString *stm = homeM.price;
        NSString *stv =[NSString stringWithFormat:@"%@%@",str, stm];
        self.price.text = stv;
        self.biao.image = [UIImage imageNamed:@"money"];
        self.biaoqian.image = [UIImage imageNamed:@"biaoqianzi"];
    }
    

    
    
    
}

//布局方法
- (void)applyLayoutAttributes:(UICollectionViewLayoutAttributes *)layoutAttributes
{
    _gname.frame = CGRectMake(5, 9, 80, 25);
    _biaoqian.frame = CGRectMake(100, 3, 70, 30);
    _biaotou.frame = CGRectMake(112, 8, 23,23 );
    _biao.frame = CGRectMake(116, 11.5, 15, 15);
    _image.frame = CGRectMake(5, 40, 65, 65);
    _image.layer.cornerRadius = self.frame.size.width / 15;
    _desc.frame = CGRectMake(0, 88, layoutAttributes.size.width, 27);
    _desc.layer.cornerRadius = layoutAttributes.size.width / 15;
    _price.frame = CGRectMake(138, 10, 27, 20);
    _language.frame = CGRectMake(5+65+5, 44, 40, 21);
    _imga.frame = CGRectMake(5+65+5, 70, 15, 15);
    _imgb.frame = CGRectMake(5+65+20,70, 15, 15);
    _imgc.frame = CGRectMake(5+65+35, 70, 15, 15);
    _imgd.frame = CGRectMake(5+65+50, 70, 15, 15);
    _imge.frame = CGRectMake(5+65+65, 70, 15, 15);
   

}




@end
